package org.jeecg.modules.bobo.common.api;

import org.jeecg.modules.bobo.common.constant.LoginConstant;
import org.jeecg.modules.bobo.common.exception.BoboException;
import org.jeecg.modules.bobo.common.util.RedisUtil;
import org.jeecg.modules.bobo.common.vo.UserModel;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: jeecg-boot-parent
 * @description: 基础api
 * @author: 三千霜
 * @create: 2020-10-27 14:25
 */

public class AbsBaseApi {

    @Autowired
    private RedisUtil redisUtil;
    protected UserModel getUserBytoken(HttpServletRequest request){
        String token = request.getHeader(LoginConstant.X_ACCESS_TOKEN);
//        UserModel userModel= JSON.parseObject(redisUtil.get(LoginConstant.PREFIX_USER_TOKEN + token), UserModel.class)  ;
        UserModel userModel= (UserModel) redisUtil.get(LoginConstant.PREFIX_USER_TOKEN + token);
        if (userModel==null){
            throw new BoboException(500,"用户未登录");
        }
        return userModel;
    }
}
